'use strict';

/**
 * @name AccountListCtrl
 * @author ZYF
 */

angular.module('metalabOperationApp').controller('AccountListCtrl', ['$scope', '$rootScope', '$state', '$stateParams', 'MetaResources', 'MetaRemind', 'MetaUtils', function ($scope, $rootScope, $state, $stateParams, MetaResources, MetaRemind, MetaUtils) {
    $scope.listCtrl = {
        data: {}
    };
    $scope.init = function () {
        $scope.openModel = MetaUtils.openModel;
        $scope.getEditData();
    };
    $scope.getEditData = function () {
        MetaResources.user.query({
                'role': 'admin'
            },
            function (data) {
                $scope.listCtrl.data = data;
            },
            function (error) {
                MetaRemind.serverError(error);
            });
    };
    $scope.degrade = function (id) {
        if (confirm('确认消除吗?')) {
            MetaResources.user.updateRole({
                id: id
            }, {
                role: 'user'
            }, function () {
                MetaRemind.success('消除权限成功');
            }, function (error) {
                MetaRemind.serverError(error);
            });
        }
    };
    $scope.toBeContinued = MetaRemind.error;
    $scope.init();
}]);
